package com.timebank.timecoin.factory;

import com.timebank.common.core.result.Result;
import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.timecoin.pojo.entity.TimeCoinTrade;
import com.timebank.timecoin.pojo.vo.TimeCoinTradeVO;
import com.timebank.timecoin.service.RemoteTimeCoinService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 智能合约 服务降级处理
 * @author shiliuyinzhen
 */
@Component
public class RemoteTimeCoinFallBackFactory implements FallbackFactory<RemoteTimeCoinService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteTimeCoinFallBackFactory.class);

    @Override
    public RemoteTimeCoinService create(Throwable throwable) {
        log.error("时间币服务调用失败:{}", throwable.getMessage());
        return new RemoteTimeCoinService(){

            @Override
            public AjaxResult createTrade(TimeCoinTrade timeCoinTrade, String source) {
                return AjaxResult.error("创建时间币交易调用失败：{}" + throwable.getMessage());
            }

            @Override
            public AjaxResult deleteTradeByIds(Long[] tradeIds, String source) {
                return AjaxResult.error("批量删除时间币交易调用失败：{}" + throwable.getMessage());
            }

            @Override
            public AjaxResult deleteTradeByVolunteerIdAndGetterId(Map<String, Long> map, String source) {
                return AjaxResult.error("根据志愿服务Id和获得者Id删除时间币交易调用失败：{}" + throwable.getMessage());
            }

            @Override
            public AjaxResult payTimeCoinByVolunteerId(Long volunteerId, String source) {
                return AjaxResult.error("根据志愿服务Id支付时间币调用失败：{}" + throwable.getMessage());
            }

            @Override
            public AjaxResult deleteTradeByVolunteerIds(Long[] volunteerIds, String source) {
                return AjaxResult.error("根据志愿服务Ids批量删除时间币交易调用失败：{}" + throwable.getMessage());
            }

            @Override
            public AjaxResult deleteTradeByUserIdsAndVolunteerId(Long[] userIds, Long volunteerId, String source) {
               return AjaxResult.error("根据用户Ids和志愿服务Id批量删除时间币交易调用失败：{}" + throwable.getMessage());
            }

            @Override
            public Result<List<TimeCoinTradeVO>> getTradeByCondition(TimeCoinTrade timeCoinTrade, String source) {
                return Result.fail("条件查询时间币交易调用失败：{}" + throwable.getMessage());
            }
        };
    }

}
